plot.QQs.brut <- function(	
			data1 = dat, 
			subset = NULL, #"ma_name == \"Hind\" & ma_type == \"affy\"",
			pobs.name = "pvalue", #c("pvalTest1", "pvalTest2")
			lim.X = NULL, ##c(xmin, xmax)
			lim.Y = NULL, ## c(ymin, ymax), 
			titre = NULL,
			couleur = F	){

qqplot <- function (x, y, plot.it = TRUE, xlab = deparse(substitute(x)), 
    ylab = deparse(substitute(y)), add.to.plot = FALSE, ...) 
{
    sx <- sort(x)
    sy <- sort(y)
    lenx <- length(sx)
    leny <- length(sy)
    if (leny < lenx) 
        sx <- approx(1:lenx, sx, n = leny)$y
    if (leny > lenx) 
        sy <- approx(1:leny, sy, n = lenx)$y
    if (plot.it)
      if(add.to.plot)
        points(sx, sy, ...)
      else
        plot(sx, sy, xlab = xlab, ylab = ylab, ...)
    invisible(list(x = sx, y = sy))
}

	



#cat('dimension des donnees');#print(dim(data1))
											
	if(!is.null(subset)) data1 <- data1[with(data1, eval(parse(text = subset))), ]
	
#cat('dimension du subset des donnees');#print(dim(data1))

numPval <- vector(length = length(pobs.name))

for(i in 1:(length(pobs.name))){

 #cat(paste("\n**********\ngraphe", i, ":", pobs.name[i], "\n**********\n"))
	pobs <- with(data1, eval(parse(text = pobs.name[i])))

	if(is.factor(pobs)) pobs <- as.numeric(levels(pobs))[pobs]

#cat(paste("nb p-values renseignees :", sum(!is.na(pobs))))

	numPval[i] <- sum(!is.na(pobs))
	
	if(is.null(lim.X))	testX <- c(min(pobs, na.rm = T), max(pobs, na.rm = T) )
		else testX <- lim.X
	
	if(is.null(lim.Y))  testY <- c(min(pobs, na.rm = T), max(pobs,na.rm = T))
		else testY <- lim.Y
	
#cat("\nlimites X : ");#print(testX)
#cat("limites Y : ");#print(testY)
	
	pobsmin <- min(pobs, na.rm = T)
	pobsmax <- max(pobs, na.rm = T)

#cat("pobsmin");#print(pobsmin)	
#cat("pobsmax");#print(pobsmax)	

	qqplot( (1:length(pobs)/(length(pobs) + 1)), #rang

#runif(length(pobs), min = pobsmin, max = pobsmax), #distribution uniforme

		pobs, 
		main = paste("QQ-plot", subset, titre, sep = "\n"), 
		ylab="observed p-value", 
		xlab="uniform p-value",
		xlim = testX,
  		ylim = testY , 
		pch = i,
		cex = 0.6, 
		col = ifelse(couleur, i ,1),
		add.to.plot = ifelse(i > 1, T, F)

)

	abline(0, 1, col="firebrick")

}

#legend
legend("bottomright", paste(pobs.name, " (N = ", numPval, ")", sep = ""), pch = 1:length(pobs.name), col = 1:length(pobs.name))


}
